package com.leecode.exercise;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: shubin_yao
 * @Date: 2022/06/14/13:01
 * @Description: 二叉树中序遍历
 */
public class MidInterTree {

    public static void main(String[] args) {
        //root = [1,null,2,3]
        Solution1 solution1 = new Solution1();
        TreeNode root = new TreeNode();
        root.val = 1;
        /*root.right = new TreeNode();
        root.right.val = 2;
        root.right.left = new TreeNode();
        root.right.left.val = 3;*/
        List<Integer> integers = solution1.inorderTraversal(root);
        System.out.println(integers);
    }
}

class Solution1 {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        list = dfs(list, root);
        return list;
    }

    public List<Integer> dfs(List<Integer> list, TreeNode root) {
        if (root == null) {
            return list;
        }
        dfs(list, root.left);
        list.add(root.val);
        dfs(list, root.right);
        return list;
    }


}
